#ifndef __FileIOWrapper_h__
#define __FileIOWrapper_h__

#define ENABLE_FILE_ACCESS_LOGGER

//////////////////////////////////////////////////////////////////////////
class CIOWrapper
{
public:
	enum IOOperation {
		IO_OPEN,
		IO_READ,
		IO_SEEK,
		IO_TELL,
		IO_CLOSE,
		IO_OPENINPAK,
		IO_READINPAK,
		IO_SEEKINPAK,
		IO_CLOSEINPAK
	};

	static void SetLoggerState(int b);
	static size_t Fread(void *pData, size_t nSize, size_t nCount, FILE *hFile,void* pInternalFile=0);
	static int Fclose(FILE * hFile);



	static FILE * Fopen(const char * file, const char * mode);

	static long FTell(FILE * hFile);
	static int Fseek(FILE * hFile, int64 seek, int mode,void *pInternalFile=0);

	static void AddLabel(const char *);

	static FILE *m_pLastFile;
	static int64 m_nFileCursorReal;
	static int64 m_nFileCursorVirtual;

	static bool m_bLockReads;
	static CryCriticalSection m_ReadCS;
};


#ifndef ENABLE_FILE_ACCESS_LOGGER
struct FileAccessLogger
{
	FILE* m_pFile;

	FileAccessLogger(CIOWrapper::IOOperation action, FILE * file, size_t size, int64 offset,void *pInternalFile) {};
	FileAccessLogger(CIOWrapper::IOOperation action, const char *strName, FILE * file, size_t size) {}
	static void RegisterFileHandle( void *pFileHandle,const char *name ) {}
	static void AddLabel(const char * label) {}
};
#else //ENABLE_FILE_ACCESS_LOGGER
struct FileAccessLogger
{
	typedef std::map<void*,string> THandleMap;

	FileAccessLogger(CIOWrapper::IOOperation action, FILE * file, size_t size, int64 offset,void *pInternalFile);
	FileAccessLogger(CIOWrapper::IOOperation action, const char *strName, FILE * file, size_t size);
	~FileAccessLogger();

	static void RegisterFileHandle( void *pFileHandle,const char *name );
	static void AddLabel(const char * label);
	static FILE* GetFile();

	static THandleMap	m_HandleMap;
	static CryCriticalSection m_HandleMapLock;
	CTimeValue m_fTime;
	CIOWrapper::IOOperation m_Action;
	const char * m_strFileName;
	void* m_pInternalFile;
	FILE * m_pFile;
	size_t m_nSize;
	int64 m_nOffset;
};
#endif //ENABLE_FILE_ACCESS_LOGGER

#endif //__FileIOWrapper_h__